<template>
  <div class="container">
    <div class="login">
      <div class="item">
        <h2>津荣智慧监控平台</h2>
      </div>
      <div class="item">
        <span>账号：</span>
        <el-input size="mini" v-model="loginId" placeholder="请输入账号" />
      </div>
      <div class="item">
        <span>密码：</span>
        <el-input
          size="mini"
          type="password"
          v-model="loginPwd"
          placeholder="请输入密码"
        />
      </div>
      <div class="item">
        <span>记住我：</span>
        <el-checkbox v-model="cmMe"></el-checkbox>
      </div>
      <div class="item">
        <span></span>
        <el-button size="mini" type="primary" @click="adminLogin"
          >登录</el-button
        >
        <el-button size="mini">取消</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { reactive, toRefs } from 'vue'
//导航访问后台Api
import { Login } from '../api/admin'
//引入路由器对象
import { useRouter } from 'vue-router'
export default {
  name: 'LoginForm',
  setup() {
    //定义登录数据
    //获取当前项目中的路由器对象
    let $router = useRouter()
    let loginData = reactive({
      loginId: '',
      loginPwd: '',
      cmMe: false,
    })
    //定义管理员登录方法
    let adminLogin = async () => {
      //解构出账号和密码
      // Login({ loginId: loginData.loginId, loginPwd: loginData.loginPwd })
      let { loginId, loginPwd } = loginData
      let success = await Login({ loginId, loginPwd })
      if (success) {
        $router.push('/menu')
      }
      //表示登录成功
    }
    //返回数据
    return {
      ...toRefs(loginData),
      adminLogin,
    }
  },
}
</script>

<style scoped lang="scss">
.container {
  width: 100vw;
  height: 100vh;
  background-color: rgb(26, 49, 65);
  display: flex;
  justify-content: center;
  align-items: center;
  .login {
    width: 400px;
    height: 400px;
    border: 1px solid rgb(185, 195, 202);
    border-radius: 6px;
    color: white;
    padding: 10px;
    .item {
      font-size: 14px;
      align-items: center;
      display: flex;
      margin: 10px 0;
      h2 {
        flex: 1;
        text-align: center;
      }
      span {
        width: 90px;
        text-align: right;
        border: 1px solid rgb(26, 49, 65);
      }
      div {
        flex: 1;
      }
    }
  }
}
</style>
